#include <iostream>

using namespace std;

const int N = 110;

int f[N][N];
int n, m, x[N], w[N], v[N];

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> x[i] >> w[i] >> v[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = 0; j <= m; j++)
		{
			f[i][j] = f[i - 1][j];
			for(int k = 1; k <= x[i] && j - k * w[i] >= 0; k++)
			{
				f[i][j] = max(f[i][j], f[i - 1][j - k * w[i]] + k * v[i]);
			}
		}
	}
	cout << f[n][m] << endl;
	return 0;
}
